define([
        'underscore',
        'app/utils/CommonUtils'
        ], function (
		_
        
    ) {

	var cookie = $.AMUI.utils.cookie;
	var cookieSetting_useruuid = "wjt_useruuid";
	var cookieSetting_username = "wjt_username";
	var cookieSetting_isAdmin = "wjt_isAdmin";
	
	return {
		initializePage:function(_needAdmin){
			var needAdmin = false;
			if(!$.isNull(_needAdmin)){
				needAdmin = _needAdmin;
			}
			var opt = {};
			var cookiesetting = this.getLoginCookie();
			if(this.notlogin(cookiesetting)){
				$.redirectTo("admin-login.html");
			}
			
			
			if(needAdmin){
				if(cookiesetting.isAdmin != "1"){
					$.redirectTo("admin-login.html");	
				}
			}

			opt.username = cookiesetting.username;
			opt.useruuid = cookiesetting.useruuid;
			opt.isAdmin = cookiesetting.isAdmin;
			
			return opt;
			
		},
		clearCookie:function(){
			cookie.unset(cookieSetting_useruuid, "/");
			cookie.unset(cookieSetting_username, "/");
			cookie.unset(cookieSetting_isAdmin, "/");
		},
		addCookie:function(){
			
		},
		getLoginCookie:function(){
			var s = {};
			s.useruuid = $.val_trim(cookie.get(cookieSetting_useruuid));
			s.username = $.val_trim(cookie.get(cookieSetting_username));
			s.isAdmin = $.val_trim(cookie.get(cookieSetting_isAdmin));
			return s;
		},
		notlogin:function(param){
			if($.isNullStr(param.useruuid)){
				return true;
			}else{
				return false;
			}
			
		},
		login:function(param){
//			var useruuid = param.useruuid;
//			var username = param.username;

			var end = new Date((new Date()).valueOf() + 7*24*60*60*1000);
			
			cookie.set(cookieSetting_useruuid, param.useruuid, end, "/");
			cookie.set(cookieSetting_username, param.username, end, "/");
			cookie.set(cookieSetting_isAdmin, param.isAdmin, end, "/");
		}
	};

});
